package com.wz.wzliving.commodity.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.wz.wzliving.commodity.service.AttrgroupService;
import com.wz.wzliving.commodity.vo.AttrGroupWithAttrsVo;
import com.wzcommon.utils.PageUtils;
import com.wzcommon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.wz.wzliving.commodity.entity.AttrEntity;
import com.wz.wzliving.commodity.service.AttrService;

import javax.annotation.Resource;


/**
 * 商品属性表
 *
 * @author wangzeng
 * @email 3107187288@qq.com
 * @date 2025-03-31 21:10:49
 */
@RestController
@RequestMapping("commodity/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);

        return R.ok().put("page", page);
    }
    @RequestMapping("/base/list/{categoryId}")

    public R baseAttrList(@RequestParam Map<String, Object> params, @PathVariable("categoryId") Long categoryId){
        PageUtils page = attrService.queryBaseAttrPage(params,categoryId);
        return R.ok().put("page", page);
    }
    @RequestMapping("/sale/list/{categoryId}")
    public R saleAttrList(@RequestParam Map<String, Object> params, @PathVariable("categoryId") Long categoryId){

        PageUtils page = attrService.querySaleAttrPage(params,categoryId);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")

    public R info(@PathVariable("attrId") Long attrId){
		AttrEntity attr = attrService.getById(attrId);

        return R.ok().put("attr", attr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody AttrEntity attr){
//
        attrService.saveAttrAndRelation(attr);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody AttrEntity attr){
		attrService.updateById(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }


}
